package ldh.im.fxbase.data.pojo;

import java.util.HashMap;
import java.util.Map;

public class ResponseResult<T> {

    private int status;
    private String msg;
    private boolean success = false;
    private T data = null;

    public static ResponseResult build() {
        return new ResponseResult();
    }

    public ResponseResult() {
    }

    public ResponseResult(int status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public ResponseResult put(String key, Object data) {
        Map<String, Object> map = null;
        if (data != null && data instanceof Map) {
            throw new RuntimeException("data已经赋值，不能改变成map");
        } else {
            map = new HashMap<>();
            data = map;
            success = true;
        }
        map.put(key, data);
        return this;
    }

    public ResponseResult(T data) {
        this.data = data;
        this.msg = "";
        this.success = true;
        this.status = 100;
    }

    public ResponseResult error(int status, String msg) {
        this.status = status;
        this.msg = msg;
        this.success = false;
        return this;
    }

    public ResponseResult success(T data) {
        this.success = true;
        this.msg = "";
        this.data = data;
        return this;
    }

    public int getStatus() {
        return status;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }
}
